package com.wxxymaker.init;

import com.blade.Blade;
import com.blade.Environment;
import com.blade.event.BeanProcessor;
import com.blade.ioc.annotation.Bean;
import com.blade.mvc.view.template.JetbrickTemplateEngine;
import com.wxxymaker.utils.Config;
import com.wxxymaker.utils.ConfigUtils;
import com.wxxymaker.utils.Const;
import com.wxxymaker.utils.SimpleCache;

@Bean
public class DaoAndView implements BeanProcessor {
    @Override
    public void processor(Blade blade) {
        Environment ev = blade.environment();
        if (ConfigUtils.isInit()) {
            Config config = (Config) SimpleCache.get(Const.configKey);
            ConfigUtils.openSQL(ev, config);
        }
        // 加载模板
        JetbrickTemplateEngine template = new JetbrickTemplateEngine();
        template.addConfig("$classpathLoader.root", ev.get("mvc.template.path", "templates"));
        template.addConfig("jetx.import.classes", "com.wxxymaker.model.entity.*");
        blade.templateEngine(template);
    }

}
